//================================================
//
//  Slavon.net menu v0,7b "write" lib
//
//   menu_x - x of "place_menu"
//   menu_y - y of "place_menu"
//   temp_menu - menu array by id (ex: menu[i].pid = 2)
//   index_menu - indexes between menu[] and temp_menu
//   menu_gen - menu (ID) already generated
//
//////////////////////////////////////////////////
//
//   TO DO:
//   1. menu[id].ori have 0,2 ; need 1,3
//   2. menu[id].type - horizontal, vertical
//   3. cellpadding - ok; cellspacing - need check
//   4. Optimization :)
//
//
//================================================



function write_menu_l1(ox, oy){
	if (!isDOM) return true;
menu_x = ox;
menu_y = oy;
write_menu_custom(0);
}
function write_menu_other(){
	if (!isDOM) return true;
}
function write_menu_custom(id){
	if (!isDOM) return true;
	var temp_menu = new Array();
	var index_menu = new Array();
	var str = '';


	for(i=0; i<menu_gen.length; i++)
		if (menu_gen[i] == id)
			return true;
	
	for(i=1; i<menu.length; i++)
		if (menu[i].pid == id){
			temp_menu[(temp_menu.length?temp_menu.length:0)] = menu[i];
			index_menu[(index_menu.length?index_menu.length:0)] = i;
		}
	if (temp_menu.length){
		if (menu_gen.length && menu[id].ori== 2){
			xx = menu[id].x + menu[id].w;
			yy = menu[id].y;
//            alert(yy);
		}else{
			xx = menu_gen.length?menu[id].x:'';
			yy = menu_gen.length?(menu[id].y + menu[id].h):'';
		}
		                                                
		if (!menu_gen.length){
str = '<table border="0" cellspacing="0" cellpadding="0">';
	for(i=0; i<temp_menu.length; i++){
if (temp_menu[i].div_style){

str += '<tr>';
str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" class="table-lmenu2-s">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="270">';
str += '<tr><td><div style="height: 0px; width: 20px"><spacer type="block" width="20"></spacer></div></td>';
str += '<td align="right" width="230"><a href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</a></td>';
str += '<td><div style="height: 0px; width: 20px"><spacer type="block" width="20"></spacer></div></td>';
str += '</tr></table>';
str += '</td>';
str += '</tr>';

//   str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '"><a href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</a></td>';
}else{
str += '<tr>';
str += '<td onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');this.className = \'table-lmenu-s\';" onmouseout="td_menu_out();this.className = \'table-lmenu\';"' + ' class="table-lmenu">';
str += '<table border="0" cellspacing="0" cellpadding="0" width="270"><tr>';
str += '<td><div style="height: 0px; width: 20px"><spacer type="block" width="20"></spacer></div></td>';
str += '<td align="right" width="230"><a href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</a></td>';
str += '<td><div style="height: 0px; width: 20px"><spacer type="block" width="20"></spacer></div></td>';
str += '</tr></table>';
str += '</td>';
str += '</tr>';

//   str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"' + '><a href="'+ temp_menu[i].url + '">' + temp_menu[i].text +'</a></td>';
        if ((temp_menu.length-1) != i ){
str += '<tr>';
str += '<td><img src="/common/img/menu/hr_2.gif" width="270" height="12" border="0" alt=""><br></td>';
str += '</tr>';
        }
}

		if (menu[index_menu[i]].div_style)
			for(k=1; k<menu.length; k++){
				if (menu[k].pid == index_menu[i]){
str += '<tr>';
str += '<td><div style="width: 0px; height: 5px"><spacer type="block" height="5"></spacer></div></td>';
str += '</tr>';
                    if (menu[k].div_style){
                    
str += '<tr>';
str += '<td><table border="0" cellspacing="0" cellpadding="0" width="270">';
str += '<tr>';
str += '<td><div style="height: 0px; width: 20px"><spacer type="block" width="20"></spacer></div></td>';
str += '<td align="right" width="230" class="lmenu2-s"><a href="'+menu[k].url+'">'  + menu[k].text + '</a></td>';
str += '<td><img src="/common/img/menu/bul_2_s.gif" width="2" height="4" hspace="9" vspace="7" border="0" alt=""></td>';
str += '</tr>';
str += '</table></td>';
str += '</tr>';
                    }else{
str += '<tr>';
str += '<td><table border="0" cellspacing="0" cellpadding="0" width="270">';
str += '<tr>';
str += '<td><div style="height: 0px; width: 20px"><spacer type="block" width="20"></spacer></div></td>';
str += '<td align="right" width="230" class="lmenu2"><a href="'+menu[k].url+'">'  + menu[k].text + '</a></td>';
str += '<td><img src="/common/img/menu/bul_2.gif" width="2" height="4" hspace="9" vspace="7" border="0" alt=""></td>';
str += '</tr>';
str += '</table></td>';
str += '</tr>';
                    }           
                }
                if ((menu.length-1) == k ){
str += '<tr>';
str += '<td><img src="/common/img/menu/hr_2.gif" width="270" height="12" border="0" alt=""><br></td>';
str += '</tr>';
                }
        	}
	}
str += '</table>';
		}else{
str = "<div id='a" + id + "' name='a" + id + "' style='width: 215px; position: absolute; left: " + xx + "px; top: " + yy + "px; visibility: visible; z-index: 999999;'>";
str += '<img src="/common/img/menu/u_t.gif" width="172" height="13" border="0" alt=""><br>';
str += '<table border="0" cellspacing="0" cellpadding="0" width="172">';
str += '<tr valign="top">';
str += '<td><div style="height: 0px; width: 7px"><spacer type="block" width="7"></spacer></div></td>';
str += '<td width="162">';
str += '<table border="0" cellspacing="0" cellpadding="0">';
			for(i=0; i<temp_menu.length; i++){
str += '<tr>';
str += '<td onclick="document.location=\'' + temp_menu[i].url + '\';" id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');this.className = \'table-umenu-s\';" onmouseout="td_menu_out();this.className = \'table-umenu\';" class="table-umenu"><table border="0" cellspacing="0" cellpadding="2" width="162">';
str += '<tr>';
str += '<td><div style="height: 17px; width: 20px"><spacer type="block" width="20" height="17"></spacer></div></td>';
str += '<td width="118"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a></td>';
str += '<td><div style="height: 17px; width: 20px"><spacer type="block" width="20" height="17"></spacer></div></td>';
str += '</tr>';
str += '</table></td>';
str += '</tr>';
            
            
// str += '<tr>';
// str += '<td id="td_' + index_menu[i] + '" name="td_' + index_menu[i] + '" onmouseover="td_menu_over(' + index_menu[i] + ');" onmouseout="td_menu_out();"><a href="' + temp_menu[i].url + '">' + temp_menu[i].text + '</a></td>';
// str += '</tr>';
                if ((temp_menu.length-1) != i ){
str += '<tr>';
str += '<td><img src="/common/img/menu/u_hr.gif" width="162" height="1" border="0" alt=""><br></td>';
str += '</tr>';
                }
			}
str += '</table>';
str += '</td>';
str += '<td background="/common/img/menu/u_bg_2.gif"><div style="height: 0px; width: 3px"><spacer type="block" width="3"></spacer></div></td>';
str += '</tr>';
str += '</table>';
str += '<img src="/common/img/menu/u_b.gif" width="172" height="7" border="0" alt=""><br>';
str += "</div>";
		}
		if(menu_gen.length){
			getRef('place_menu2').innerHTML += str;
		}else{
			getRef('place_menu').innerHTML = str;
		}
		for(i=0; i<temp_menu.length; i++){
			if (menu_gen.length){
				menu[index_menu[i]].x = getRef("a" + id).offsetLeft + getRef("td_" + index_menu[i]).offsetLeft;
				menu[index_menu[i]].y = getRef("a" + id).offsetTop + getRef("td_" + index_menu[i]).offsetTop;
			}else{
				menu[index_menu[i]].x = menu_x + getRef("place_menu").offsetLeft + getRef("td_" + index_menu[i]).offsetLeft + 10;
				menu[index_menu[i]].y = menu_y + getRef("place_menu").offsetTop + getRef("td_" + index_menu[i]).offsetTop + 4;
			}
			menu[index_menu[i]].h = getRef("td_" + index_menu[i]).offsetHeight;
			menu[index_menu[i]].w = getRef("td_" + index_menu[i]).offsetWidth;
		}
		menu_gen[(menu_gen.length?menu_gen.length:0)] = id;
	}
}

function clear_all(){
	if (!isDOM) return true;
menu_show = new Array();
menu_gen = new Array();
menu_id = "";
menu_status = 0;
getRef('place_menu2').innerHTML = "";
getRef('place_menu').innerHTML = "";
write_menu_l1(menu_x, menu_y);
}